pull: Only take up one terminal line for status output
authorColin Walters <walters@verbum.org>
Tue, 17 Jul 2012 02:35:18 +0000 (22:35 -0400)
committerColin Walters <walters@verbum.org>
Tue, 17 Jul 2012 02:35:18 +0000 (22:35 -0400)
And print total bytes transferred at the end.

src/ostree/ostree-fetcher.c
src/ostree/ostree-fetcher.h
src/ostree/ostree-pull.c

index 7ab15ed789d5eb5270a5c8e06711cbe2a00e3f38..dcabf6eb8b05fc3b898bbe7e2b4350a5663be4c4 100644 (file)
@@ -334,3 +334,9 @@ ostree_fetcher_query_state_text (OstreeFetcher              *self)
   else
     return g_strdup_printf ("Idle");
 }
+
+guint64
+ostree_fetcher_bytes_transferred (OstreeFetcher       *self)
+{
+  return self->total_downloaded;
+}
index d32ea6f921927675d1a30b164f0b645189fb148d..803db7298a756de334def9848d2234eebf9f03dc 100644 (file)
@@ -49,6 +49,8 @@ OstreeFetcher *ostree_fetcher_new (GFile *tmpdir);
 
 char * ostree_fetcher_query_state_text (OstreeFetcher              *self);
 
+guint64 ostree_fetcher_bytes_transferred (OstreeFetcher       *self);
+
 void ostree_fetcher_request_uri_async (OstreeFetcher         *self,
                                        SoupURI               *uri,
                                        GCancellable          *cancellable,
index 156facf08369d0fbcf0da959a7c1da036ce7b0f6..96c967a489cb2720f9d84d0be652349c56e9a0d3 100644 (file)
@@ -104,6 +104,7 @@ typedef struct {
   gboolean      caught_error;
 
   gboolean      stdout_is_tty;
+  guint         last_padding;
 } OtPullData;
 
 static SoupURI *
@@ -165,7 +166,18 @@ uri_fetch_update_status (gpointer user_data)
 
   fetcher_status = ostree_fetcher_query_state_text (pull_data->fetcher);
   g_string_append (status, fetcher_status);
-  g_print ("%s\n", status->str);
+  if (status->len > pull_data->last_padding)
+    pull_data->last_padding = status->len;
+  else
+    {
+      guint diff = pull_data->last_padding - status->len;
+      while (diff > 0)
+        {
+          g_string_append_c (status, ' ');
+          diff--;
+        }
+    }
+  g_print ("%c8%s", 0x1B, status->str);
 
   g_string_free (status, TRUE);
 
@@ -202,14 +214,22 @@ run_mainloop_monitor_fetcher (OtPullData   *pull_data)
 {
   GSource *update_timeout = NULL;
 
-  update_timeout = g_timeout_source_new_seconds (1);
-  g_source_set_callback (update_timeout, uri_fetch_update_status, pull_data, NULL);
-  g_source_attach (update_timeout, g_main_loop_get_context (pull_data->loop));
-  g_source_unref (update_timeout);
+  if (pull_data->stdout_is_tty)
+    {
+      g_print ("%c7", 0x1B);
+      update_timeout = g_timeout_source_new_seconds (1);
+      g_source_set_callback (update_timeout, uri_fetch_update_status, pull_data, NULL);
+      g_source_attach (update_timeout, g_main_loop_get_context (pull_data->loop));
+      g_source_unref (update_timeout);
+    }
   
   g_main_loop_run (pull_data->loop);
 
-  g_source_destroy (update_timeout);
+  if (pull_data->stdout_is_tty)
+    {
+      g_print ("\n");
+      g_source_destroy (update_timeout);
+    }
 }
 
 typedef struct {
@@ -1428,6 +1448,7 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   SoupURI *summary_uri = NULL;
   GKeyFile *config = NULL;
   char **configured_branches = NULL;
+  guint64 bytes_transferred;
 
   memset (pull_data, 0, sizeof (*pull_data));
 
@@ -1554,6 +1575,8 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
   if (!ostree_repo_prepare_transaction (pull_data->repo, NULL, error))
     goto out;
 
+  g_print ("Analyzing objects needed...\n");
+
   g_hash_table_iter_init (&hash_iter, commits_to_fetch);
   while (g_hash_table_iter_next (&hash_iter, &key, &value))
     {
@@ -1620,6 +1643,12 @@ ostree_builtin_pull (int argc, char **argv, GFile *repo_path, GError **error)
                                                   cancellable, error))
     goto out;
 
+  bytes_transferred = ostree_fetcher_bytes_transferred (pull_data->fetcher);
+  if (bytes_transferred > 0)
+    {
+      g_print ("%" G_GUINT64_FORMAT " KiB transferred\n", (guint64)(bytes_transferred / 1024.0));
+    }
+
   ret = TRUE;
  out:
   if (pull_data->loop)